package com.elitel.frame.base.component;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSON;
//import com.elitel.common.redis.RedisDbIndex;
//import com.elitel.common.redis.service.RedisCacheService;
import com.elitel.frame.base.service.SysProjectService;
import com.elitel.frame.main.entity.vo.ZTreeDataModelVo;

@Component("redisCacheProjectService")
public class RedisCacheProjectService {

    //    @Autowired
//    private RedisCacheService redisCacheService;
    @Autowired
    private SysProjectService sysProjectService;
//    @Autowired
//    private RedisConnInfo redisConnInfo;

    /**
     * <pre>getProjectServerTreeList(获取工程服务树)
     * @author：FanWenquan
     * @date：2017年11月27日 上午11:43:20
     * @return</pre>
     * <p>
     * modify by guoyanfei on 2019/07/17
     * 新增验证redis连通性
     *
     * @see
     */
    @Cacheable(cacheNames = CacheConfig.DEFAULT, key = "'TREE_PROJECT_SERVICE'")
    public List<ZTreeDataModelVo> getProjectServerTreeList() {
//		int xx = RedisDbIndex.value;
//		List<ZTreeDataModelVo> zTreeDataModelVos = new ArrayList<ZTreeDataModelVo>();
//		if(redisConnInfo.checkConnReids()) {
//			String ztreestr="";
//			String key = "TREE_PROJECT_SERVICE";
//			if(redisCacheService.stringExists(key,xx)){
//				ztreestr = redisCacheService.getObject(key, xx);
//				zTreeDataModelVos = (List<ZTreeDataModelVo>)JSON.parseArray(ztreestr,ZTreeDataModelVo.class);
//			}else{
//				zTreeDataModelVos = sysProjectService.getProjectServerTreeList();
//				ztreestr = JSON.toJSONString(zTreeDataModelVos);
//				redisCacheService.saveObject(key, ztreestr, xx);
//			}
//		}else {
//			zTreeDataModelVos = sysProjectService.getProjectServerTreeList();
//		}

        List<ZTreeDataModelVo> zTreeDataModelVos = sysProjectService.getProjectServerTreeList();
        return zTreeDataModelVos;
    }

    /**
     * <pre>freshProjectServerTree(刷新工程服务树)
     * @author：FanWenquan
     * @date：2017年11月27日 上午11:51:10   </pre>
     * <p>
     * modify by guoyanfei on 2019/07/17
     * 新增验证redis连通性
     *
     * @see
     */
    @CachePut(cacheNames = CacheConfig.DEFAULT, key = "'TREE_PROJECT_SERVICE'")
    public List<ZTreeDataModelVo> freshProjectServerTree() {
//        if (!redisConnInfo.checkConnReids()) return;
//
//        int xx = RedisDbIndex.value;
//        String key = "TREE_PROJECT_SERVICE";
//        List<ZTreeDataModelVo> zTreeDataModelVos = sysProjectService.getProjectServerTreeList();
//        String ztreestr = JSON.toJSONString(zTreeDataModelVos);
//        redisCacheService.saveObject(key, ztreestr, xx);
        List<ZTreeDataModelVo> zTreeDataModelVos = sysProjectService.getProjectServerTreeList();
        return zTreeDataModelVos;

    }
}
